// index.js
var api = require("../../api.js"),
  app = getApp();
var r;
Page({
  data: {
    userListInfo: [],
    pageIndex: 2,
    sHeight: '',
    loading: false, //第一次加载，设置true  
    loadingComplete: false, //把“没有数据”设为false，隐藏  
    isFromSearch: true,
  },
  /**  生命周期函数--监听页面加载 */
  onLoad: function(options) {
    this.setData({
      id: options.id,
    })
  },
  onShow: function() {
    var that = this;
    if (getApp().globalData.userInfo != null) {
      wx.showLoading({
        title: '数据加载中',
      });
      // 获取报名列表
      var t = new Object();
      var replayarr = [];
      t.page_index = "1", t.page_size = "10", t.other_id = that.data.id;

      wx.request({
        url: api.order.enrolls,
        data: t,
        success: function(res) {
          if (res.statusCode == 200 && res.data.code == 200) {
            var n = res.data.data;
            console.log('url -- > ' + api.order.enrolls)
            console.log(n)
            if (n.length != 0) {
              var checkStatus = '';
              n.length < 10 ? checkStatus = false : true;
              setTimeout(() => {
                wx.hideLoading();
                that.setData({
                  userListInfo: n,
                  loading: checkStatus,
                  loadingComplete: checkStatus,
                  hidden: false
                });
              }, 500)
            } else {
              setTimeout(() => {
                wx.hideLoading();
                that.setData({
                  loadingComplete: false,
                  loading: false,
                  hidden: true
                })
              }, 500)
            }
          }
        }
      });
    };
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.showNavigationBarLoading(), console.log("下拉刷新"), this.show(), setTimeout(function() {
      wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
    }, 1500);
  },

  loading: function() {
    var that = this;
    wx.showNavigationBarLoading();
    var t = new Object();
    t.page_index = that.data.page_index, t.page_size = "10", t.other_id = that.data.id;
    wx.request({
      url: api.order.enrolls,
      data: t,
      success: function(res) {
        if (res.statusCode == 200 && res.data.code == 200) {
          var n = res.data.data;
          if (n.length > 0) {
            r.data.isFromSearch ? dataList = n : dataList = that.data.userListInfo.concat(n)
            setTimeout(() => {
              that.setData({
                userListInfo: dataList,
                loading: true,
              });
            }, 500)
          } else {
            setTimeout(() => {
              that.setData({
                loadingComplete: true,
                loading: false,
              })
            }, 500)
          }
        }
      }
    });
  },
  /** 页面上拉触底事件的处理函数 */
  onReachBottom: function() {
    let _that = this
    if (_that.data.loading && !_that.data.loadingComplete) {
      _that.setData({
        page_index: _that.data.page_index + 1,
        isFromSearch: false
      });
      _that.loading();
    };
  },
})